package com.situ.day21;

import com.situ.day20.Student;
import com.situ.day20.Teacher;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class Generic {

    @Test
    public void testGeneric() throws Exception {
        // 集合的声明
        List list = new ArrayList();
        list.add("China");
        list.add(1);

        // 集合的使用
        String str = (String) list.get(0);
        System.out.println(str);
    }

    @Test
    public void testGeneric2() throws Exception {
        // 集合的声明
        List<String> list = new ArrayList<String>();
        list.add("China");
        //list.add(1);

        // 集合的使用
        String str = list.get(0);
        System.out.println(str);

        List<Integer> list1 = new ArrayList<>();
    }


    public Student add1(Student student, Teacher teacher) {
        return null;
    }

    public <K,T> K add(K k, T t) {
        return k;
    }

    @Test
    public void test1() {
        Double result1 = add(1.0, 1);
        Float result2 = add(1.0f, 1);
        String result3 = add("abc", 1);
    }

    @Test
    public void test2() {
        Student student = new Student();
        BaseDao<Student> baseDao1 = new BaseDao<>();
        baseDao1.add(student);
        baseDao1.update(student);

        Teacher teacher = new Teacher();
        BaseDao<Teacher> baseDao2 = new BaseDao<>();
        baseDao2.add(teacher);
        baseDao2.update(teacher);
    }
}
